package acm.华中农业;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class J {
    public static void main(String[] args) throws IOException {
        BufferedReader in =new BufferedReader(new InputStreamReader(System.in));
        int count=Integer.parseInt(in.readLine());
        String[] read =null;
        while (count-->0){
            read=in.readLine().split(" ");
            int n=Integer.parseInt(read[0]);
            int k=Integer.parseInt(read[1]);
            System.out.println(fun(n, k));
        }

    }
    static {
//        System.out.println(fun(70,3));
//        for (int i =5; i < 10; i++) {
//            System.out.println(i+"："+fun(i,4));
//        }
    }
    public static long fun(int n,int k){
        int limit= (int) Math.pow(10,k);
        long res=1;
        long pre=1;
        long curr=0;
        for (int i = 2; i <= n; i++) {
            while (pre%10==0){
                pre/=10;
            }
            while (pre>limit){
                pre%=limit;
            }
            curr=pre*i;
            pre=curr;
            res*=curr;
            while (res%10==0){
                res/=10;
            }
            if (res>limit){
                res%=limit;
            }
        }
        return res%limit;
    }

    static
    class AReader {
        private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        private StringTokenizer tokenizer = new StringTokenizer("");
        private String innerNextLine() {
            try {
                return reader.readLine();
            } catch (IOException ex) {
                return null;
            }
        }
        public boolean hasNext() {
            while (!tokenizer.hasMoreTokens()) {
                String nextLine = innerNextLine();
                if (nextLine == null) {
                    return false;
                }
                tokenizer = new StringTokenizer(nextLine);
            }
            return true;
        }
        public String nextLine() {
            tokenizer = new StringTokenizer("");
            return innerNextLine();
        }
        public String next() {
            hasNext();
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

//        public BigInteger nextBigInt() {
//            return new BigInteger(next());
//        }
        // 若需要nextDouble等方法，请自行调用Double.parseDouble包装
    }
}
